package com.dykj.fireFighting.server.base.rescue.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.dykj.fireFighting.api.base.rescue.entity.RescueInfo;
import com.dykj.fireFighting.api.base.rescue.service.IRescueInfoService;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.server.base.rescue.mapper.RescueInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 救援单位
 *
 * @Author JacksonTu
 * @Date 2021-06-29 13:20:35
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class RescueInfoServiceImpl extends BaseServiceImpl<RescueInfoMapper, RescueInfo> implements IRescueInfoService {


    @Override
    public List<RescueInfo> getList(String unitId) {
        LambdaQueryWrapper<RescueInfo> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(unitId)) {
            wrapper.eq(RescueInfo::getUnitId, unitId);
        }
        wrapper.eq(RescueInfo::getIsDel, 1);

        return this.baseMapper.selectList(wrapper);
    }

    @Override
    public List<RescueInfo> getList(String unitId, int type, String name) {
        LambdaQueryWrapper<RescueInfo> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(unitId)) {
            wrapper.eq(RescueInfo::getUnitId, unitId);
        }
        if (StringUtils.isNotBlank(name)) {
            wrapper.like(RescueInfo::getName, name);
        }
        wrapper.eq(RescueInfo::getIsDel, 1);
        wrapper.eq(RescueInfo::getType, type);

        return this.baseMapper.selectList(wrapper);
    }

    @Override
    public boolean deleteById(String id) {
        UpdateWrapper<RescueInfo> wrapper = new UpdateWrapper<>();
        RescueInfo rescueInfo = new RescueInfo();
        rescueInfo.setIsDel(0);

        wrapper.eq("id", id);
        this.baseMapper.update(rescueInfo, wrapper);

        return true;
    }
}
